home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / amos-tools / eaissue3a / text / fonts_tutorial.asc < prev    next >
Encoding:
Text File  |  1996-07-13  |  16.6 KB  |  401 lines

  1. ü
  2.                           AMOS Tutorial - IFF Fonts
  3.                           -------------------------
  4.     
  5. þ
  6.                         Part 1 - What is an IFF font?
  7.                           Part 2 - How does it work
  8.                       Part 3 - Creating an example font
  9.                        Part 4 - Creating your own fonts
  10.     
  11. ù
  12.     This tutorial has been typed out by Andrew "Mushroom" Kellett, of
  13.     Mushroom PD (C) March 1996. All rights reserved. If you wish to use
  14.     this article in any other disk magazine, you must first get my
  15.     permission in writing. I must also receive a FULL copy of the magazine
  16.     that it appears in.
  17.     
  18. ú
  19.     If you would like to get in touch with me about Extreme AMOS, Mushroom
  20.     PD or any other AMOS related matter, you can get in touch with me at
  21.     the below address. If you decide to telephone, please do it after 7pm,
  22.     when I am not as busy, and no later than 11pm, after all, we all need
  23.     our beauty sleep! The address is :
  24.     
  25. ÿ
  26. û
  27.                           Andrew "Mushroom" Kellett
  28.                                  Mushroom PD
  29.                             32 Castleton Crescent
  30.                                    Gamesley
  31.                                    Glossop
  32.                                   Derbyshire
  33.                                    SK13 9TH
  34.                                    ENGLAND
  35.     
  36. ü
  37.          Telephone (01457) 857502   E-Mail:  mush@sneech.demon.co.uk
  38.     
  39. ý
  40.         All letters sent to me will be replied to as soon as possible. As
  41.     well as this tutorial, there are other tutorials available :
  42.     
  43. û
  44.                        Creating AMOS Graphic Equalizers
  45.                           Creating Simple Databases
  46.                         Creating an AMOS Tracker demo
  47.               Identifying different music formats in AMOS (62K!)
  48.     
  49.     
  50. ÿ
  51. þ
  52.         If you would like any of the above tutorials, then you can send me
  53.     an SAE and a disk. If you fill the disk full of your own AMOS games
  54.     and utilitys, either compiled or in source code for inclusion in the
  55.     library, then you need not include the SAE, as I will send you the
  56.     stuff back. Alternatively, you can exchange a disk of your own
  57.     programs for a Mushroom disk in the library. Remember to state the
  58.     Mushroom disk number when ordering.
  59.     
  60. ù
  61.         Have you written any AMOS tutorials which you would like included
  62.     in Extreme AMOS? They can be of any kind of subject, as long as it is
  63.     AMOS. It could be anything from the use of a simple command, right
  64.     through to a large programming diary you have completed. The address
  65.     to send all of your ASCII files, along with any source code that
  66.     accompany's the tutorial, is listed above. You will receive a FREE
  67.     copy of the first issue that your tutorial appears in.
  68.     
  69.     
  70.     
  71.     
  72.     
  73. ÿ
  74. ú
  75.                                     PART 1
  76.                                     ~~~~~~
  77. ü
  78.                             What is an IFF font ?
  79.     
  80. þ
  81.         I daresay you have loaded and played a game, where there is a nice
  82.     attractive font that appears on the screen, to display either the
  83.     instructions or maybe the hi-scores. With a hi-score table, there are
  84.     endless possibilities for the names that you enter into it. One way of
  85.     doing this, is to read a font stored on the disk, but displaying these
  86.     can be a bit slow, so the need for an IFF font is called.
  87.     
  88.         A IFF font is a screen full of letters and numbers, that can be
  89.     called at any time from within the program, to be displayed anywhere
  90.     on any screen. These characters are all coloured in the same style as
  91.     the rest, to classify the screen as an IFF font screen. This screen is
  92.     then packed, and is saved to the disk along with the program. IFF
  93.     fonts use a lot less space than if you just had lot's of screens with
  94.     the IFF font displayed as instructions, or everything placed in a
  95.     sprite bank to be displayed later on.
  96.     
  97. ÿ
  98. þ
  99.         There are 2 kinds of IFF font, the first being a simple "Square"
  100.     layout, where each of the characters has the same height and width.
  101.     These are the easiest kinds of font to work with. The second kind of
  102.     font is a non-proportional font, in which the width or height of the
  103.     font can change with each of the characters. These fonts take a little
  104.     more time to prepare, but still look just as good.
  105.     
  106.         Fonts can range from simple 3 or 4 pixel squared images, right
  107.     through to a full screen in size. The number of possibilities that can
  108.     be acheived from the font is endless.
  109.     
  110.     
  111.     
  112.     
  113.     
  114.     
  115.     
  116.     
  117.     
  118.     
  119. ÿ
  120. ú
  121.                                     PART 2
  122.                                     ~~~~~~
  123.     
  124. ü
  125.                          How does an IFF font work ?
  126.     
  127. þ
  128.         An IFF font is really very simple to use, in any kind of program.
  129.     The routines which I have supplied you will demonstrate how easy it is
  130.     to install a font into your program. An IFF font is read from a grid
  131.     in memory. Each grid space can either be a "Square" font, or each
  132.     piece can vary in size. The program creates an array with all the X
  133.     and Y coordinates for each of the possible pieces, which is called by
  134.     the other routines. There is also another part to the array which
  135.     contains the width of all the different characters available, which is
  136.     more usefull when the font is non-proportional.
  137.     
  138.         Let me try and give you an example. Let's say that you decided to
  139.     use an array called FONT. The program would create 5 offsets from that
  140.     array, FONTX, FONTY, FONTXX, FONTYY, AND FONTS. FONTX and FONTY
  141.     represent the top left hand coordinates of the top of the character in
  142.     the list. FONTXX and FONTYY hold the bottom right-hand coordinates for
  143. ÿ
  144. þ
  145.     the character. FONTS hold the width (in pixels) of the character just
  146.     defined. Another way of doing this, is to eliminate FONTS completely,
  147.     and use the algorythym FONTXX-FONTX, but the way I have described is
  148.     easier to follow.
  149.     
  150.         The next step, is to create a string of all the available
  151.     characters in your font. Let's say "ABCDEFGHIJKLMNOPQRSTUVWXYZ". Now,
  152.     when the INSTR command is used against the letter we are looking for,
  153.     it will return with the number inside the string. Say you were looking
  154.     for the letter "D", then INSTR would return with 4. So, it would use
  155.     the SCREEN COPY FONTX(4),FONTY(4),FONTXX(4),FONTYY(4) To destination..
  156.     and paste the letter "D" into place. It is highly important that the
  157.     string containing all the letters is typed in the same way the
  158.     information is entered into the array, otherwise the letters will
  159.     come out different than what you have requested.
  160.     
  161.         The routines I have developed, have been coded to allow you, the
  162.     user, to apply as little AMOS knowledge as possible. All you have to
  163.     do, is assign the POSX and POSY graphics coordinates on the screen, for
  164.     where you want the text to go, and the string you wish printed. If you
  165. ÿ
  166. þ
  167.     decide to use the centring routines, then the POSX coordinate is not
  168.     needed, as the program will automatically work out the position for
  169.     you.
  170.     
  171.         All the routines in ALL my fonts use the same kind of parameters
  172.     for different functions. Some of the routines have scrollers, and
  173.     centering routines, which can easily be called in your programs. The
  174.     variables I tend to use the most are :
  175.     
  176. û
  177.                  TEX$ - The string to be drawn on the screen
  178.             POSX - The X coordinate of the destination of the font
  179.             POSY - The Y coordinate of the destination of the font
  180.            SC$ - The text which is to be scrolled across the screen
  181.            NUM - The character being drawn, according to the array
  182.                   _SCREEN - The screen number to be drawn on
  183.     
  184. þ
  185.         I have eliminated the need to add loads of parameters onto a
  186.     procedure call, saving space in the text buffer, so the program runs
  187.     off the CURRENT settings of all the variables called. It is important
  188.     that you make these values GLOBAL, or SHARED, otherwise they will be
  189. ÿ
  190. þ
  191.     read as 0 by the routine.
  192.     
  193.         Any other variables are called from within the routine, and are
  194.     not really all that important. If centering the piece of text, then
  195.     you only need assign the POSY value with the true number, and the TEX$
  196.     string to be displayed. _SCREEN does not need to be changed more than
  197.     once unless you are working on a different screen number.
  198.     
  199.         If using the scroller, you can determine how you would like to
  200.     leave the routine. I usually place a small routine in the code which
  201.     will allow me to leave the routine if the mouse button is pressed, and
  202.     I have taken this out of some of the examples. Remember, CTRL+C will
  203.     break you out of the program, and back to the editor.
  204.     
  205.         If you define the statements as global values, you can also
  206.     maintain the values of the last drawing, which is handy when on an
  207.     options screen for example. You could have "Quit? (Y/N)", and then
  208.     when the key is pressed, you could recall the draw routine and print
  209.     the character, before moving onto the next piece of text.
  210.     
  211. ÿ
  212. þ
  213.         One thing which I like about IFF fonts, is the fact that they can
  214.     be used in any screen mode, providing the font has enough colours, and
  215.     does not contain more than the desired screen resolution. This means
  216.     that you can fit more text onto a line if you go into hi-res mode, or
  217.     less, more detailed characters on the screen if you decide to opt for
  218.     a lower resolution.
  219.     
  220.         Because the program uses SCREEN COPY, the results it produces are
  221.     almost instantaneously, especially if there is not much to copy. If
  222.     the font is small and are quite a few lines to be done, then it may
  223.     take a couple of seconds, but it is even faster when compiled. The
  224.     only drawback, is that you can't merge the font onto an already-drawn
  225.     background, as it copy's the black bits from the font screen, over to
  226.     the destination screen. In order to get round that problem, you will
  227.     need to use GET BOB, and PASTE BOB, which is slower to use than SCREEN
  228.     COPY.
  229.     
  230.     
  231.     
  232.     
  233. ÿ
  234. ú
  235.                                     Part 3
  236.                                     ~~~~~~
  237.     
  238. ü
  239.                    How to create an example font that works
  240.     
  241. þ
  242.         OK then, I am now going to create a simple program, which will
  243.     first create a non-proportianate font. Also included, is a scroll
  244.     routine, which when activated, will scroll a piece of text across the
  245.     screen using that IFF font.
  246.     
  247. ý
  248.                          Load and run EXAMPLE_01.AMOS
  249.     
  250. þ
  251.         As you can see, the font scrolls across the screen. If the screen
  252.     was not in DOUBLE BUFFER mode, it would flicker and jump quite badly.
  253.     You can also see all the DATA statements, which make up this kind of
  254.     font. Now, I think it is time for a proportional font.
  255.     
  256. ý
  257.                          Load and run EXAMPLE_02.AMOS
  258.     
  259. þ
  260.         This is a nice 16 colour font, which means that it can also be
  261. ÿ
  262. þ
  263.     used on a hires screen, with some good results. Look at the DATA
  264.     statements, and see how I built up the size array, using the TEMPA and
  265.     TEMPB arrays alongside it. Again, I have chosen to use the scroller
  266.     routine.
  267.     
  268.         Now, I think it is about time I demonstrated how simple it is to
  269.     use the _CEN and _DRAW routines from within a font. The next example
  270.     uses the same font as in example 2, but will centre a few words. If
  271.     you look at the listing in which you need to actually perform the
  272.     task, you will see that you only need to assign 2 values before
  273.     actually running - The text string to be printed, and the vertical
  274.     position of the text. The draw routine is called from within the
  275.     centering routine, but you can actually move this around, and call it
  276.     seperate of the routine.
  277.     
  278. ý
  279.                          Load and run EXAMPLE_03.AMOS
  280.     
  281. þ
  282.         See, dead simple. The hardest part of the entire thing, is
  283.     defining the font to create. Once the routines are installed, it is so
  284.     easy to use, in all kinds of screenmodes. This fonts work in Hires.
  285. ÿ
  286. ú
  287.                                     Part 4
  288.                                     ~~~~~~
  289.     
  290. ü
  291.                       How to create your own IFF fonts!
  292.     
  293. þ
  294.         Hmm, you do need a paint package to do this, although I am sure
  295.     that there is a program somewhere in the library that will actually
  296.     make the data statements for you. If not, I shall get onto making one
  297.     very soon.
  298.     
  299.         First of all, you will need to place all of the possible
  300.     characters onto a single screen, without them lapping over each
  301.     other's boundary's, otherwise you will get ghosted letters appearing
  302.     on the screen. It is best that you use a single screen, to any size
  303.     you need, as you would need to create another element in the font
  304.     arrays in order to determine which screen you are going to copy from.
  305.     Now you will need to go into personal paint, or any other paint
  306.     package that you have, which will allow you to magnify the picture,
  307.     and show the X and Y coordinates of the screen. Now, write down a list
  308.     of all the possible characters available, and get the coordinates by
  309. ÿ
  310. þ
  311.     following these instructions :
  312.     
  313. ü
  314.       Proportional fonts
  315.       ~~~~~~~~~~~~~~~~~~
  316.     
  317. û
  318.         Simply write down each horizontal coordinate of each letter, by
  319.     letting the crosshairs of the mouse overlap onto the first pixel on
  320.     the top, and the left-hand side of the letter. Write down the
  321.     coordinates. Now do the same for the bottom right of the character,
  322.     but ensure that the crosshairs are NOT overlapping onto any of the
  323.     pixels. You must also write down the 4 coordinates for all the
  324.     characters on the left hand side of the screen, and use an array
  325.     similar to what I used, with the across number of letters going
  326.     across, and the down going down in the loop. Also make a note of the
  327.     width of the character in pixels, to be used instead of NINES()
  328.     
  329. ü
  330.       Non-Proportional fonts
  331.       ~~~~~~~~~~~~~~~~~~~~~~
  332.     
  333. û
  334.         Unlike the above, you must write down all 4 coordinates for each
  335. ÿ
  336. û
  337.     letter, and also the width (in pixels) of each letter, so the program
  338.     can add the space accordingley. Take the coordinates using the same
  339.     method as above, and draw a line from the left hand side of the char,
  340.     to the right, and the screen should tell you how many pixels it takes
  341.     (before you let go of the mouse). Pressing UNDO should remove the
  342.     line, unless you clicked on something else first.
  343.     
  344.         Once you have all of your coordinates, you can place them into
  345.     DATA statements like I did, spacing them out, with each letter being
  346.     on one line during testing, to iron out any small bugs that you may
  347.     have overlooked. When you know it is working correctly, you can then
  348.     reduce the number of lines.
  349.     
  350.     
  351. ù
  352.         Well, I think that just about covers it. As you know, every month
  353.     I give away new IFF font programs, so you should never be short of an
  354.     IFF font to use in your own programs. Most of the IFF fonts were drawn
  355.     by people other than myself, yet the program was written by me, so
  356.     remember that in your credits should you decide to use any of my
  357.     routines.
  358. ÿ
  359.     
  360. ù
  361.         If you want to know more about any other AMOS subject, then why
  362.     not drop me a line at the above address. I also have other tutorials
  363.     available (all with source) which cover a whole array of different
  364.     subjects :
  365.     
  366. û
  367.                               Graphic Equalizers
  368.                            Tracker Tutorial Prt. 1
  369.                            Tracker Tutorial Prt. 2
  370.                                Databases Prt. 1
  371.                                Databases Prt. 2
  372.                                   IFF Fonts
  373.     
  374. ø
  375.         You can get any of these tutorials by sending an SAE and a disk,
  376.     or 4 first class stamps, to me at the address above. If you are
  377.     sending a disk, then why not fill it with some AMOS PD so I can place
  378.     it in the library. All letters will be replied to as soon as possible.
  379.     
  380.     
  381.     
  382. ÿ
  383. û
  384.         If you would like to contribute any articles to Extreme AMOS, then
  385.     include them on the disk as well. Remember, any articles I use, you
  386.     will receive a FREE copy of the first issue they appear in. I would
  387.     prefer it if you sent AMOS articles, but other things such as reviews
  388.     etc. are welcome.
  389.     
  390.         I would especially like things like programming diaries, and
  391.     routines, which are explained in detail, to cover special FX on the
  392.     screen, or some other form of really usefull routine. The list of
  393.     possibilities is endles !!
  394.     
  395. ú
  396.     [Andrew "Mushroom" Kellett]
  397.     
  398. ÷
  399. EOF
  400.  
  401.